import { Injectable, Inject } from '@nestjs/common';
import { Model } from 'mongoose';
import { DBCONSTANTS } from '@/database/db.constants';
import { Demand } from './interface/demand.interface';

@Injectable()
export class DemandService {
  @Inject(DBCONSTANTS.demandModel)
  private readonly demandModel: Model<Demand>;

  /**
   * 获取当前激活团队的需求列表
   * @param userId 用户id
   * @param teamId 团队id
   */
  async getDeamndList(userId: string, teamId: string): Promise<Demand> {
    return await this.demandModel.find({
      userId,
      teamId
    });
  }
  /**
   * 新建需求
   * @param demand 需求对象
   */
  async createDemand(demand: Demand): Promise<Demand> {
    const data = new this.demandModel(demand);
    return await data.save();
  }
}
